"""
    Author:
    Date: 2020-04-01

    银联管理类
"""
import hashlib

from utils import haibao_util

def create_order_no(uid, rmb, out_trade_no_prefix):
    """ 创建银联公众号充值订单ID """
    code, msg, info = haibao_util.create_unipay_mp_pay_order(uid, rmb, out_trade_no_prefix)
    if code != 0:
        return None

    out_trade_no = info.get('out_trade_no', None) if info else None
    return out_trade_no


def create_order_no_for_alipay_h5(uid, rmb, out_trade_no_prefix):
    """ 创建银联支付宝H5充值订单ID """
    code, msg, info = haibao_util.create_unipay_ali_h5_pay_order(uid, rmb, out_trade_no_prefix)
    if code != 0:
        return None

    out_trade_no = info.get('out_trade_no', None) if info else None
    return out_trade_no


def build_sign(payload, secret):
    """ 构造签名 """
    temp = '&'.join(['%s=%s' % (key, payload[key]) for key in sorted(payload)])
    temp += secret
    sign = hashlib.md5(temp.encode('utf-8')).hexdigest().upper()
    return sign


if __name__ == '__main__':
    print('ok')
